package com.h2.ref.server.user;

import java.util.ArrayList;
import java.util.Collection;

import com.h2.ref.server.user.dao.IUserDao;
import com.h2.ref.server.user.model.User;

public class DUserService implements IUserService {
   
   private IUserDao _userDao;
   
   private Collection<IUserListener> _userListeners =
         new ArrayList<IUserListener>();
   ////
   ////
   
   public User getActiveUser() {
      return getUserDao().findByUserName("default");
   }

   @Override
   public User getActiveUser(Boolean password) {
      return getActiveUser();
   }

   @Override
   public void update(User user) {
      throw new IllegalArgumentException("Method not supported");
   }

   @Override
   public void delete(User user) {
      // TODO Auto-generated method stub
      
   }

   @Override
   public User find(User user) {
      return findByUserId(user.getId());
   }

   @Override
   public User findByUserId(Integer userId) {
      return getUserDao().findByUserName("default");
   }
   
   public User findByUserName(String name) {
      return getUserDao().findByUserName("default");
   }

   @Override
   public User findByEmail(String email) {
      return getUserDao().findByUserName("default");
   }

   @Override
   public User search(String name) {
      return findByUserName(name);
   }

   /**
    * @return the userDao
    */
   public IUserDao getUserDao() {
      return _userDao;
   }

   /**
    * @param userDao the userDao to set
    */
   public void setUserDao(IUserDao userDao) {
      _userDao = userDao;
   }

   @Override
   public User addUser(User user) {
      return getUserDao().findByUserName("default");
   }

   @Override
   public User addRegisteredUser(User user, Boolean active) {
      return addUser(user);
   }

   @Override
   public Collection<User> getUsers() {
      Collection<User> results = new ArrayList<User>();
      results.add(findByUserName("default"));
      return results;
   }

   @Override
   public Collection<IUserListener> getUserListeners() {
      return _userListeners;
   }

}
